<template>
  <div id="best_seller">
    <h2>畅销图书</h2>
    <ul class="book_list">
      <li v-for="(item,index) of bookList"
          @click="showDetails(item.isbn)"
          :key="item._id">
        <span class="book_index">{{index+1}}</span>
        <span class="book_name">《{{item.name}}》</span>
        <span class="book_author">作者：{{item.author}}</span>
        <span class="book_price">￥{{item.price.toFixed(2)}}</span>
      </li>
    </ul>
  </div>
</template>

<script>
import {getAllBooks} from "../../network/home";

export default {
  name: "BestSeller",
  data(){
    return{
      bookList:[],
    }
  },
  created() {
    getAllBooks().then((result)=>{
      console.log(result);
      // console.log()
      this.bookList=result.data.data;
    }).catch((reason)=>{
      console.log(reason);
    })
  },
  methods:{
    showDetails(isbn){
      this.$router.push(`/bookdetails/${isbn}`)
    }
  },
}
</script>

<style scoped>
#best_seller{
  position: relative;
  width: 100%;
}
#best_seller h2{
  text-align: center;
  line-height: 50px;
  font-size: 30px;

}
.book_list{
}
.book_list li{
  display: flex;
  height: 50px;
  line-height: 50px;
  background-image: linear-gradient( 325deg, #FAD7A1 66%, #E96D71 0);
  margin: 20px 0;
  transition: all 200ms;
}
.book_list li:hover{
  background-image: linear-gradient( 325deg, #FAD7A1 66%, #189FFF 0);
  color: #ffffff;
  font-weight: bolder;
}
.book_list li span{
  text-align: center;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.book_index{
  padding: 0 20px;
  font-size: 30px;
  color: #ffffff;
  font-weight: bold;
}
.book_name{
  width: 380px;
  font-size: 22px;
}
.book_author{
  width: 500px;
  margin-left: 120px;
}
.book_price{
  flex: 1;
  font-size: 21px;
  color: #E96D71;
  font-weight: bolder;
}
</style>
